package com.example.perplonews.a_a_mvp.presenter.presenters

import BasePresenter
import IPresenter
import Tokencontract
import com.example.perplonews.a_b_utils.LjlUtils
import com.example.shopping2.a_a_entity.BaseEntity
import com.example.shopping2.a_a_entity.TokenEntity
import com.example.shopping2.a_c_network.SpUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers


class TokenPresenter(myModel: Tokencontract.Token_MyModel, myView: Tokencontract.Token_MyView) :
    BasePresenter<Tokencontract.Token_MyModel, Tokencontract.Token_MyView>(myModel, myView),
    IPresenter {
    fun requestToken(){
        var map: HashMap<String,Any> = HashMap()
        map.put("imie",""+System.currentTimeMillis())
        mymodel.requestToken(map)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(this)
    }

    override fun onNext(t: BaseEntity) {
        var tokenEntity = t as TokenEntity
        if (tokenEntity.status.equals("200")){
            LjlUtils.Ljl_Loge("-------"+tokenEntity.getValues()?.token)
            SpUtils.saveData("token",""+tokenEntity.getValues()?.token)
            myview.refresh()
        }

    }
}